#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#               Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#
### BEGIN INIT INFO
# Provides:          pathfinderd
# Required-Start:    $remote_fs $syslog dbus
# Required-Stop:     $remote_fs $syslog dbus
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Pathfinder X.509 Path Discovery and Validation Service 
# Description:       Enable RFC3280 compliant X.509 path discovery and 
#		     validation service via dbus.
### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/pathfinderd
NAME="pathfinderd"
DESC="Pathfinder X.509 PDVal Service"

test -x $DAEMON || exit 0

LOGDIR=/var/log/pathfinder
PIDFILE=/var/run/$NAME.pid
DODTIME=1                   # Time to wait for the server to die, in seconds
	                    # If this value is set too low you might not
                            # let some servers to die gracefully and
                            # 'restart' will not work

# Include pathfinder defaults if available
if [ -f /etc/default/pathfinderd ] ; then
	. /etc/default/pathfinderd
fi

. /lib/lsb/init-functions

case "$1" in
  start)
	log_begin_msg "Starting $DESC: "
	start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec $DAEMON -- $DAEMON_OPTS
	log_end_msg $?
	;;
  stop)
	log_begin_msg "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--exec $DAEMON
	log_end_msg $?
	;;
  force-stop)
	log_begin_msg "Forcefully stopping $DESC: "
		killall -KILL $DAEMON
	log_end_msg $?
	;;
  #reload)
	#
	#	If the daemon can reload its config files on the fly
	#	for example by sending it SIGHUP, do it here.
	#
	#	If the daemon responds to changes in its config file
	#	directly anyway, make this a do-nothing entry.
	#
	# echo "Reloading $DESC configuration files."
	# start-stop-daemon --stop --signal 1 --quiet --pidfile \
	#	/var/run/$NAME.pid --exec $DAEMON
  #;;
  force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart" except that it does nothing if the
	#   daemon isn't already running.
	# check wether $DAEMON is running. If so, restart
	start-stop-daemon --stop --quiet --pidfile \
		/var/run/$NAME.pid --exec $DAEMON \
	&& $0 restart \
	|| exit 0
	;;
  restart)
        log_begin_msg "Restarting $DESC: "
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--exec $DAEMON
	[ -n "$DODTIME" ] && sleep $DODTIME
	start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec $DAEMON -- $DAEMON_OPTS
	log_end_msg $?
	;;
  status)
    log_begin_msg "$LABEL is "
    if running ;  then
        log_success_msg "running"
    else
        log_failure_msg " not running."
        exit 1
    fi
    ;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	log_success_msg "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
	exit 1
	;;
esac

exit 0
